package com.wuliu.servlet;

import com.wuliu.dao.NewsClassDAO;
import com.wuliu.dao.impl.NewsClassDAOImpl;
import com.wuliu.model.NewsClass;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/news_class/add")
public class AdminNewsClassAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("/WEB-INF/view/admin/news_class_add.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name=req.getParameter("name");
        String img=req.getParameter("img");
        NewsClass newsClass=new NewsClass(null,name,img);
        NewsClassDAO newsClassDAO=new NewsClassDAOImpl();
        newsClassDAO.add(newsClass);
        resp.sendRedirect("/admin/news_class");
    }

}
